package com.example.administrator.yunniuusedcar.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * 首页ViewPager的适配器
 * Created by Administrator on 2017/11/28.
 * @author LQW
 */
public class MainAdapter extends FragmentPagerAdapter {

    private List<Fragment> fragments;
    private String[] datas;

    public MainAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }

    public MainAdapter(FragmentManager fm, List<Fragment> fragments, String[] datas) {
        super(fm);
        this.fragments = fragments;
        this.datas = datas;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount()
    {
        return fragments.size();
    }

    // 显示TabLayout时用到
    @Override
    public CharSequence getPageTitle(int position) {
        if (datas == null)
            return "";

        return datas[position];
    }
}

